package org.lq.er.view.Information;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import org.lq.er.entity.Exam_information;
import org.lq.er.entity.Student;
import org.lq.er.entity.Subject;
import org.lq.er.service.Exam_informationService;
import org.lq.er.service.StudentService;
import org.lq.er.service.SubjectService;
import org.lq.er.service.impl.Exam_informationServiceImpl;
import org.lq.er.service.impl.StudentServiceImpl;
import org.lq.er.service.impl.SubjectServiceImpl;

import javax.swing.JLabel;
import javax.swing.JOptionPane;

import java.awt.Font;
import java.awt.SystemColor;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.JButton;
import javax.swing.BoxLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import java.util.List;
import java.awt.event.ActionEvent;
import javax.swing.DefaultComboBoxModel;
import javax.swing.border.LineBorder;
import java.awt.Color;
import javax.swing.border.TitledBorder;
import javax.swing.border.EtchedBorder;
/**
 * 	查看报名信息视图
 * @author 韩伟伟
 *
 * @package org.lq.er.view.Information
 */
public class V_checkApply extends JFrame {

	private JPanel contentPane;
	private JTextField stu_name;
	private JTextField stu_grade;
	private JTextField stu_id;
	private JTextField status;
	private JTextField stu_no;
	private JTextField stu_card_id;
	private String [] arr;
	private static Exam_informationService ps = new Exam_informationServiceImpl();
	private static StudentService sts = new StudentServiceImpl();
	private SubjectService subjectService = new SubjectServiceImpl();
	private JTextField seatnum;
	private JTextField textsubjectName;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					V_checkApply frame = new V_checkApply();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public V_checkApply() {
		setTitle("等级考试报名系统");
		setResizable(false);
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 488, 345);
		setLocationRelativeTo(null);
		contentPane = new JPanel();
		contentPane.setBackground(Color.white);
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		
		JPanel panel = new JPanel();
		contentPane.add(panel, BorderLayout.CENTER);
		panel.setLayout(null);
		
		JLabel lblNewLabel = new JLabel("查看报名信息");
		lblNewLabel.setForeground(SystemColor.textHighlight);
		lblNewLabel.setFont(new Font("宋体", Font.PLAIN, 25));
		lblNewLabel.setBounds(0, 0, 166, 49);
		panel.add(lblNewLabel);
		
		JPanel panel_1 = new JPanel();
		panel_1.setBounds(0, 37, 466, 272);
		panel.add(panel_1);
		panel_1.setLayout(null);
		
		JLabel lblNewLabel_1_1 = new JLabel("姓名：");
		lblNewLabel_1_1.setFont(new Font("宋体", Font.PLAIN, 14));
		lblNewLabel_1_1.setBounds(10, 81, 48, 32);
		panel_1.add(lblNewLabel_1_1);
		
		stu_name = new JTextField();
		stu_name.setColumns(10);
		stu_name.setBounds(54, 87, 80, 21);
		panel_1.add(stu_name);
		
		JLabel lblNewLabel_1 = new JLabel("班级：");
		lblNewLabel_1.setFont(new Font("宋体", Font.PLAIN, 14));
		lblNewLabel_1.setBounds(159, 81, 48, 32);
		panel_1.add(lblNewLabel_1);
		
		stu_grade = new JTextField();
		stu_grade.setColumns(10);
		stu_grade.setBounds(207, 87, 80, 21);
		panel_1.add(stu_grade);
		
		JLabel lblNewLabel_1_2 = new JLabel("科目：");
		lblNewLabel_1_2.setFont(new Font("宋体", Font.PLAIN, 14));
		lblNewLabel_1_2.setBounds(308, 81, 48, 32);
		panel_1.add(lblNewLabel_1_2);
		List<Subject> list = subjectService.findAll();
		System.out.println(list);
		arr = new String[list.size()];
		for (int i = 0; i < arr.length; i++) {
			arr[i] = list.get(i).getSubjectName();
		}
		
		JLabel lblNewLabel_1_3 = new JLabel("身份证号：");
		lblNewLabel_1_3.setFont(new Font("宋体", Font.PLAIN, 14));
		lblNewLabel_1_3.setBounds(10, 127, 80, 32);
		panel_1.add(lblNewLabel_1_3);
		
		stu_id = new JTextField();
		stu_id.setEditable(false);
		stu_id.setColumns(10);
		stu_id.setBounds(78, 133, 209, 21);
		panel_1.add(stu_id);
		
		JLabel lblNewLabel_2 = new JLabel("状态：");
		lblNewLabel_2.setFont(new Font("宋体", Font.PLAIN, 14));
		lblNewLabel_2.setBounds(10, 169, 48, 32);
		panel_1.add(lblNewLabel_2);
		
		status = new JTextField();
		status.setEditable(false);
		status.setColumns(10);
		status.setBounds(54, 175, 80, 21);
		panel_1.add(status);
		
		JPanel panel_3 = new JPanel();
		panel_3.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED, new Color(255, 255, 255), new Color(160, 160, 160)), "\u641C\u7D22", TitledBorder.LEADING, TitledBorder.TOP, null, Color.DARK_GRAY));
		panel_3.setBounds(10, 10, 456, 79);
		panel_1.add(panel_3);
		panel_3.setLayout(null);
		
		JLabel lblNewLabel_1_1_1 = new JLabel("学号：");
		lblNewLabel_1_1_1.setBounds(10, 29, 42, 16);
		lblNewLabel_1_1_1.setFont(new Font("宋体", Font.PLAIN, 14));
		panel_3.add(lblNewLabel_1_1_1);
		
		stu_no = new JTextField();
		stu_no.setBounds(62, 27, 86, 21);
		stu_no.setColumns(10);
		panel_3.add(stu_no);
		
		JLabel lblNewLabel_1_3_1 = new JLabel("身份证号：");
		lblNewLabel_1_3_1.setFont(new Font("宋体", Font.PLAIN, 14));
		lblNewLabel_1_3_1.setBounds(158, 21, 80, 32);
		panel_3.add(lblNewLabel_1_3_1);
		
		stu_card_id = new JTextField();
		stu_card_id.setColumns(10);
		stu_card_id.setBounds(225, 27, 139, 21);
		panel_3.add(stu_card_id);
		
		JButton btnNewButton_3 = new JButton("搜索");
		btnNewButton_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
//--------------------搜索并显示------------------		
				String stucard = stu_card_id.getText();
				String stuno = stu_no.getText();
				
				Exam_information byStu_Id = (Exam_information) ps.getByStu_Id(stucard);
				Student byId = sts.getById(Integer.valueOf(stuno).intValue());//字符串转int
				if (byId!=null&&byStu_Id!=null) {
					stu_name.setText(byId.getName());
					stu_grade.setText(byId.getClasses());
					textsubjectName.setText(subjectService.findById(byStu_Id.getSubject_id()).getSubjectName());
					stu_id.setText(byStu_Id.getStu_id());
					seatnum.setText(byStu_Id.getSeat_num()+"");
					status.setText(tostatus(byStu_Id));
					reset();
				}else {
					JOptionPane.showMessageDialog(V_checkApply.this, "抱歉，没有查询到哦！", "错误", JOptionPane.ERROR_MESSAGE);
				}
			}
		});
		btnNewButton_3.setBounds(377, 26, 68, 23);
		panel_3.add(btnNewButton_3);
		
		JButton btnNewButton_2_1 = new JButton("重置");
		btnNewButton_2_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				resetAll();
			}
		});
		btnNewButton_2_1.setBounds(340, 174, 73, 23);
		panel_1.add(btnNewButton_2_1);
		
		JLabel lblNewLabel_3 = new JLabel("座号:");
		lblNewLabel_3.setBounds(153, 178, 35, 15);
		panel_1.add(lblNewLabel_3);
		
		seatnum = new JTextField();
		seatnum.setBounds(194, 175, 66, 21);
		panel_1.add(seatnum);
		seatnum.setColumns(10);
		
		textsubjectName = new JTextField();
		textsubjectName.setBounds(366, 87, 66, 21);
		panel_1.add(textsubjectName);
		textsubjectName.setColumns(10);
	}
	
	public static String tostatus(Exam_information byStu_Id) {
		String str = "";
		int status_check = byStu_Id.getStatus_check();
		int status_pay = byStu_Id.getStatus_pay();
		if (status_check == 0) {
			str = "尚未报名";
		}else {
			if(status_pay == 0) {
				str = "未支付";
			} else {
				str = "报名成功";
			}
		}
		return str;
	}
	
	/**
	 * 	重置搜索窗体里的数据
	 */
	public void reset() {
		stu_no.setText("");
		stu_card_id.setText("");
	}
	
	public void resetAll() {
		stu_no.setText("");
		stu_card_id.setText("");
		stu_name.setText("");
		stu_grade.setText("");
		stu_id.setText("");
		status.setText("");
	}
	
}
